﻿<%@ Page Title="" Language="C#" MasterPageFile="~/template_faa/master/faa_main.Master" AutoEventWireup="true" %>

<asp:Content ID="Content4" ContentPlaceHolderID="head" runat="server">
    <link rel="stylesheet" type="text/css" href="../ascx/easyui/demo/demo.css"/>
    <link rel="stylesheet" type="text/css" href="../css/left_nav.css"/>
    <script type="text/javascript" src="../scripts/datagrid-detailview.js"></script>
    <script type="text/javascript" src="../scripts/left_nav.js"></script>
    
    <script type="text/javascript" id="for datagrid">
        var editIndex = undefined;
        var editType = 0;   //0初始值，1表示新增，2表示修改
        var saveUrl = 'save_THLXgx.ashx';
        var updateUrl = 'update_THLXgx.ashx';
        var destroyUrl = 'destroy_THLXgx.ashx';

        /*上一行是否结束编辑*/
        function endEditing() { 
            if (editIndex == undefined) { return true }
            if ($('#dataGrid_id').datagrid('validateRow', editIndex)) {
                /*alert(1);
                var ed = $('#dataGrid_id').datagrid('getEditor', { index: editIndex, field: 'jhclxName' });
                alert(2);
                var jhclxName = $(ed.target).combobox('getText');
                alert(3);
                $('#dataGrid_id').datagrid('getRows')[editIndex]['jhclxName'] = jhclxName;
                $('#dataGrid_id').datagrid('endEdit', editIndex);*/
                editIndex = undefined;
                return true;
            } else {
                return false;
            }
        } 

        function onClickRow(index) {
            if (editIndex != index) {
                if (!endEditing()) {
                    $('#dataGrid_id').datagrid('selectRow', editIndex);
                    alert("请完成本行编辑");
                }
            }
        }

        /*对选中行执行编辑操作*/
        function edit() {
            var curIndex = getRowNumber();
            if (curIndex == -1) {
                alert("请选择一行进行编辑！");
            }
            
            if (editIndex != curIndex) {
                if (endEditing()) {
                    //开始编辑并设置编辑类型
                    $('#dataGrid_id').datagrid('selectRow', curIndex).datagrid('beginEdit', curIndex);
                    editIndex = curIndex;
                    editType = 2;
                } else {
                    $('#dataGrid_id').datagrid('selectRow', editIndex);
                }
            }          
        }
 
        //新增一行数据
        function append(){  
            if (endEditing()){  
                $('#dataGrid_id').datagrid('appendRow',{});
                editIndex = $('#dataGrid_id').datagrid('getRows').length - 1;
                
                //开始编辑，并设置修改类型
                $('#dataGrid_id').datagrid('selectRow', editIndex)
                        .datagrid('beginEdit', editIndex);
                editType = 1;
            }
        }  
        
        function remove(){  
            if (editIndex == undefined){return}  
            $('#dataGrid_id').datagrid('cancelEdit', editIndex)  
                    .datagrid('deleteRow', editIndex);  
            editIndex = undefined;
        }

        function accept() {
            if (editIndex != undefined) {
                $('#dataGrid_id').datagrid('endEdit', editIndex);
                $('#dataGrid_id').datagrid('acceptChanges');
                var row = $('#dataGrid_id').datagrid('getSelected');
                var url = undefined;
                switch (editType) {
                    case 0:
                        break;
                    case 1:
                        url = saveUrl;
                        break;
                    case 2:
                        url = updateUrl;
                        break;
                    default:
                        alert("Error!");
                }
                if (url != undefined) {
                    // 发送到服务器
                    var test = createQueryString(row);
                    alert(test["jclxId"]);
                    $.post(url, createQueryString(row), function(result) {
                        if (result == 'SUCCESS') {
                            $('#dataGrid_id').datagrid('acceptChanges');
                            
                            // 服务器同步后，编辑类型归零
                            editType = 0;
                            alert("保存成功");
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: '同步数据库失败'
                            });
                        }

                    });
                }
            }
        }  
        
        /*取消操作*/
        function reject(){  
            $('#dataGrid_id').datagrid('rejectChanges');
            editIndex = undefined;
            editType = 0;
        }  
        
        function getChanges(){  
            var rows = $('#dataGrid_id').datagrid('getChanges');  
            alert(rows.length+' rows are changed!');
        }

        /*获取选中行的行号*/
        function getRowNumber() {
            var row = $('#dataGrid_id').datagrid("getSelected");
            var rowIndex = $('#dataGrid_id').datagrid("getRowIndex", row);
            return rowIndex;
        }

        /*给定行，创建查询对象*/
        function createQueryString(row) {
            var jclxId = encodeURI(row["jclxId"]);
            var jclxName = encodeURI(row["jclxName"]);
            var jhclxName = encodeURI(row["jhclxName"]);
            var thclxName = encodeURI(row["thclxName"]);
            var nbyjName = encodeURI(row["nbyjName"]);
            var nbejName = encodeURI(row["nbejName"]);
            var nbsjName = encodeURI(row["nbsjName"]);
  
            var queryString = {};
            if (jclxId != undefined) {  
                queryString["jclxId"] = jclxId;
            }
            if (jclxName != undefined) {
                queryString["jclxName"] = jclxName;
            }
            if (jhclxName != undefined) {
                queryString["jhclxName"] = jhclxName;
            }
            if (thclxName != undefined) {
                queryString["thclxName"] = thclxName;
            }
            if (nbyjName != undefined) {
                queryString["nbyjName"] = nbyjName;
            }
            if (nbejName != undefined) {
                queryString["nbejName"] = nbejName;
            }
            if (nbsjName != undefined) {
                queryString["nbsjName"] = nbsjName;
            }

            return queryString;
        }
    </script>  
    
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="body_left" runat="server">
    <div id="navigator">
        <ul id="listUL">
            <li><a href="#">基元系统管理</a></li>
            <li><a href="#">行政检查管理</a>
                <ul class="myHide">
                    <li><a href="#">1</a></li>
                    <li><a href="#">2</a></li>
                </ul>
            </li>
            <li><a href="#">统计分析管理</a>
                <ul class="myHide">
                    <li><a href="#">执法统计管理</a></li>
                    <li><a href="#">安全统计管理</a></li>
                    <li><a href="#">生产统计管理</a></li>
                </ul>
            </li>
            <li><a href="#">用户管理</a>
                <ul class="myHide">
                    <li><a href="#">用户信息管理</a></li>
                    <li><a href="#">用户权限管理</a></li>
                </ul>
            </li>
            <li><a href="#">信息发布管理</a></li>
        </ul>
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="body_right_top" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="body_right_bottom" runat="server">
    <!--主表格-->
    <table id="dataGrid_id" class="easyui-datagrid" title="通航生产类型-与基础类型对应关系" style="width:800px;height:auto"  
            data-options="  
                iconCls: 'icon-edit',  
                singleSelect: true,  
                toolbar: '#dataGrid_toolbar_id',  
                url: 'getTHLXGXByJC.ashx',
                onClickRow: onClickRow
            ">  
        <thead>  
            <tr>  
                <th data-options="field:'jclxId',width:80,
                        editor:{
                            type:'validatebox',
                            options:{
                                required:true
                            }
                        }">基础类型ID</th> 
                <th data-options="field:'jclxName',width:80,
                        editor:{
                            type:'validatebox',
                            options:{
                                required:true
                            }
                        }">基础类型</th>  
                <th data-options="field:'jhclxName',width:120,  
                        formatter:function(value,row){  
                            return row.jhclxName;  
                        },  
                        editor:{  
                            type:'combobox',  
                            options:{  
                                valueField:'jhclxId',  
                                textField:'jhclxName',  
                                url:'getJHCLXForCombo.ashx', 
                                required:true  
                            }  
                        }">对应计划处月报类型</th>  
                 <th data-options="field:'thclxName',width:120,  
                        formatter:function(value,row){  
                            return row.thclxName;  
                        },  
                        editor:{  
                            type:'combobox',  
                            options:{  
                                valueField:'thclxId',  
                                textField:'thclxName',  
                                url:'getTHCLXForCombo.ashx',  
                                required:true  
                            }  
                        }">对应通航处月报类型</th>  
                <th data-options="field:'nbyjName',width:120,  
                        formatter:function(value,row){  
                            return row.nbyjName;  
                        },
                        editor:{  
                            type:'combobox',  
                            options:{  
                                valueField:'nbyjId',  
                                textField:'nbyjName',  
                                url:'getNBYJLXForCombo.ashx',  
                                required:true  
                            }  
                        }">对应年报一级类型</th>  
                <th data-options="field:'nbejName',width:120,  
                        formatter:function(value,row){  
                            return row.nbejName;  
                        },  
                        editor:{  
                            type:'combobox',  
                            options:{  
                                valueField:'nbejId',  
                                textField:'nbejName',  
                                url:'getNBEJLXForCombo.ashx',  
                                required:true  
                            }  
                        }">对应年报二级类型</th>  
                <th data-options="field:'nbsjName',width:120,  
                        formatter:function(value,row){  
                            return row.nbsjName;  
                        },  
                        editor:{  
                            type:'combobox',  
                            options:{  
                                valueField:'nbsjId',  
                                textField:'nbsjName',  
                                url:'getNBSJLXForCombo.ashx',  
                                required:true  
                            }  
                        }">对应年报三级类型</th>  
            </tr>
        </thead>  
    </table>  
    
    <div id="dataGrid_toolbar_id" style="height:auto">  
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="append()">新增</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="edit()">修改</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="remove()">删除</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="accept()">保存</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="reject()">取消</a>  
    </div>      

</asp:Content>
